//
//  CUploadView.m
//  HCHK_iphone
//
//  Created by yilong zhang on 12-1-10.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CUploadView.h"

//============================================================================================================================

@implementation CUploadView

@synthesize delegate;
@synthesize m_TableView;
@synthesize m_Name;
@synthesize m_Addr;
@synthesize m_AddrBtn;
@synthesize m_ResName;
@synthesize m_Type;
@synthesize m_AddrInfo;
@synthesize m_Image;
@synthesize m_ImgCnt;
@synthesize m_ImgList;
@synthesize m_ImgListPanel;
@synthesize m_Sum;
@synthesize m_Commit;
@synthesize m_SharePanel;
@synthesize m_ShareCur;
@synthesize m_nShareType;
@synthesize m_bIsDraft;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        UIImageView *bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        bg.image = [UIImage imageNamed:@"appbg.jpg"];
        [self addSubview:bg];
        [bg release];
        
        m_Type = 1;
        m_nShareType = -1;
        m_bIsDraft = NO;
        
        //UINavigationBar *toolbar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 51)]; 
        UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 51)];
        view.image = [UIImage imageNamed: @"barbg.png"];
        [self addSubview:view];
        //[toolbar addSubview:view];
        [view release];
    
        //UINavigationItem *item = [[UINavigationItem alloc] init];
        //[toolbar pushNavigationItem:item animated:NO];
        //[item release];
        
        /*UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 32)];
        title.textAlignment = UITextAlignmentCenter;
        title.backgroundColor = [UIColor clearColor];
        title.font = [UIFont boldSystemFontOfSize:18];
        title.text = @"好吃客";
        item.titleView = title;
        [title release];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 0, 60, 32);
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        [btn setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
        [btn setTitle:@"返回" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(CancelUpload) forControlEvents:UIControlEventTouchUpInside];
        item.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:btn] autorelease];
        
        UIView *m_Seg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 90, 31)];*/
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(10, 6, 70, 38);
        //btn.titleLabel.font = [UIFont systemFontOfSize:13];
        [btn setBackgroundImage:[UIImage imageNamed:@"save.png"] forState:UIControlStateNormal];
        //[btn setTitle:@"保存" forState:UIControlStateNormal];
        //[btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        btn.tag = 0;
        [btn addTarget:self action:@selector(SegClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        //item.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:btn] autorelease];
        
        btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(self.frame.size.width-80, 6, 70, 38);
        //btn.titleLabel.font = [UIFont systemFontOfSize:13];
        [btn setBackgroundImage:[UIImage imageNamed:@"drop.png"] forState:UIControlStateNormal];
        //[btn setTitle:@"继续" forState:UIControlStateNormal];
        //[btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        btn.tag = 1;
        [btn addTarget:self action:@selector(SegClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        //item.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:btn] autorelease];
        //[m_Seg addSubview:btn];
        
        //item.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:m_Seg] autorelease];
        //[m_Seg release];
        
        //toolbar.barStyle = UIBarStyleBlackOpaque;
        //[self addSubview:toolbar];
        //[toolbar release];
        //[toolbar drawRect:toolbar.frame];
        
        UIImageView *m_TopLog = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hchk.png"]];
        m_TopLog.frame = CGRectMake(0, 0, 110, 36);
        m_TopLog.center= CGPointMake(self.frame.size.width/2, view.frame.size.height/2-2);
        [self addSubview:m_TopLog];
        [m_TopLog release];
        
        //image
        UIImageView *imgback = [[UIImageView alloc] initWithFrame:CGRectMake(0, m_TopLog.frame.size.height+10, 102, 130)];
        imgback.image = [UIImage imageNamed:@"p-cover.png"];
        [self addSubview:imgback];
        [imgback release];
        
        m_Image = [[UIImageView alloc] initWithFrame:CGRectMake(7, 10, 90, 110)];
        m_Image.layer.masksToBounds = YES;
        m_Image.layer.cornerRadius = 6;
        m_Image.backgroundColor = [UIColor clearColor];
        //m_Image.image = [UIImage imageNamed:@"1.jpg"];
        [imgback addSubview:m_Image];
        [m_Image release];
        
        UIImageView *part = [[UIImageView alloc] initWithFrame:CGRectMake(-1, m_TopLog.frame.size.height+5, 30, 30)];
        part.image = [UIImage imageNamed:@"part-up.png"];
        [self addSubview:part];
        [part release];
        
        part = [[UIImageView alloc] initWithFrame:CGRectMake(imgback.frame.origin.x+imgback.frame.size.width-26, imgback.frame.origin.y+imgback.frame.size.height-23, 30, 25)];
        part.image = [UIImage imageNamed:@"part-down.png"];
        [self addSubview:part];
        [part release];
        
        //imgcnt
        part = [[UIImageView alloc] initWithFrame:CGRectMake(71, 52, 26, 26)];
        part.image = [UIImage imageNamed:@"moredraft.png"];
        [self addSubview:part];
        [part release];
        
        m_ImgCnt = [[UILabel alloc] initWithFrame:part.frame];
        m_ImgCnt.backgroundColor = [UIColor clearColor];
        m_ImgCnt.font = [UIFont systemFontOfSize:18];
        m_ImgCnt.textColor = [UIColor whiteColor];
        m_ImgCnt.textAlignment = UITextAlignmentCenter;
        m_ImgCnt.text = @"6";
        [self addSubview:m_ImgCnt];
        [m_ImgCnt release];
        
        //name
        UIImageView *bgimg = [[UIImageView alloc] initWithFrame:CGRectMake(109, imgback.frame.origin.y+8, 206, 30)];
        bgimg.image = [UIImage imageNamed:@"foodname.png"];
        [self addSubview:bgimg];
        [bgimg release];
        
        m_Name = [[UITextField alloc] initWithFrame:CGRectMake(162, bgimg.frame.origin.y+2, 148, 30)];
        //m_Name.placeholder = @"美食名称";
        m_Name.font = [UIFont systemFontOfSize:15];
        m_Name.backgroundColor = [UIColor clearColor];
        m_Name.delegate = self;
        m_Name.returnKeyType = UIReturnKeyDone;
        m_Name.keyboardType = UIKeyboardTypeDefault;
        m_Name.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [self addSubview:m_Name];
        [m_Name release];
        
        bgimg = [[UIImageView alloc] initWithFrame:CGRectMake(109, 87, 211, 2)];
        bgimg.image = [UIImage imageNamed:@"line.png"];
        [self addSubview:bgimg];
        [bgimg release];
        
        //resname
        bgimg = [[UIImageView alloc] initWithFrame:CGRectMake(109, 90, 206, 30)];
        bgimg.image = [UIImage imageNamed:@"resname.png"];
        [self addSubview:bgimg];
        [bgimg release];
        
        m_ResName = [[UITextField alloc] initWithFrame:CGRectMake(180, bgimg.frame.origin.y+2, 130, 30)];
        //m_ResName.placeholder = @"餐馆名";
        m_ResName.font = [UIFont systemFontOfSize:15];
        m_ResName.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        m_ResName.backgroundColor = [UIColor clearColor];
        m_ResName.returnKeyType = UIReturnKeyDone;
        m_ResName.delegate = self;
        [self addSubview:m_ResName];
        [m_ResName release];
        
        bgimg = [[UIImageView alloc] initWithFrame:CGRectMake(109, 123, 211, 2)];
        bgimg.image = [UIImage imageNamed:@"line.png"];
        [self addSubview:bgimg];
        [bgimg release];
        
        //address
        bgimg = [[UIImageView alloc] initWithFrame:CGRectMake(109, 127, 206, 30)];
        bgimg.image = [UIImage imageNamed:@"foodaddr.png"];
        [self addSubview:bgimg];
        [bgimg release];
        
        m_Addr = [[UITextField alloc] initWithFrame:CGRectMake(162, bgimg.frame.origin.y+2, 148, 30)];
        //m_Addr.placeholder = @"地址";
        //m_Addr.enabled = NO;
        m_Addr.font = [UIFont systemFontOfSize:15];
        m_Addr.returnKeyType = UIReturnKeyDone;
        m_Addr.delegate = self;
        m_Addr.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        m_Addr.backgroundColor = [UIColor clearColor];
        [self addSubview:m_Addr];
        [m_Addr release];
        
        m_AddrBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        m_AddrBtn.frame = CGRectMake(175, 160, 143, 39);
        [m_AddrBtn setBackgroundImage:[UIImage imageNamed:@"foodmap.png"] forState:UIControlStateNormal];
        m_AddrBtn.tag = 3;
        [m_AddrBtn addTarget:self action:@selector(OnButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:m_AddrBtn];
        
        //sum
        bgimg = [[UIImageView alloc] initWithFrame:CGRectMake((self.frame.size.width-305)/2, 195, 305, 68)];
        bgimg.image = [UIImage imageNamed:@"foodsum.png"];
        [self addSubview:bgimg];
        [bgimg release];
        
        m_Sum = [[UITextView alloc] initWithFrame:CGRectMake((self.frame.size.width-300)/2, 200, 300, 60)];
        m_Sum.backgroundColor = [UIColor clearColor];
        m_Sum.font = [UIFont systemFontOfSize:12];
        m_Sum.returnKeyType = UIReturnKeyDone;
        m_Sum.delegate = self;
        m_Sum.clipsToBounds = YES;
        //m_Sum.scrollEnabled = NO;
        [self addSubview:m_Sum];
        [m_Sum release];
        
        //commit
        m_Commit = [UIButton buttonWithType:UIButtonTypeCustom];
        m_Commit.frame = CGRectMake(248, 269, 70, 38);
        [m_Commit setBackgroundImage:[UIImage imageNamed:@"commitfood.png"] forState:UIControlStateNormal];
        [m_Commit addTarget:self action:@selector(OnCommitButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:m_Commit];
        
        //share
        m_SharePanel = [[UIView alloc] initWithFrame:CGRectMake((frame.size.width-195)/2, 313, 195, 117)];
        [self addSubview:m_SharePanel];
        [m_SharePanel release];
        m_SharePanel.backgroundColor = [UIColor clearColor];
        
        bgimg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 28, 28)];
        bgimg.image = [UIImage imageNamed:@"chooseblank.png"];
        [m_SharePanel addSubview:bgimg];
        [bgimg release];
        
        bgimg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 35, 28, 28)];
        bgimg.image = [UIImage imageNamed:@"chooseblank.png"];
        [m_SharePanel addSubview:bgimg];
        [bgimg release];
        
        bgimg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 70, 28, 28)];
        bgimg.image = [UIImage imageNamed:@"chooseblank.png"];
        [m_SharePanel addSubview:bgimg];
        [bgimg release];
        
        btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(35, 0, 135, 28);
        btn.tag = 0;
        [btn setBackgroundImage:[UIImage imageNamed:@"uploadsina.png"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(OnShareBtnDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_SharePanel addSubview:btn];
        
        btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame =CGRectMake(35, 35, 135, 28);
        btn.tag = 1;
        [btn setBackgroundImage:[UIImage imageNamed:@"uploadqq.png"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(OnShareBtnDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_SharePanel addSubview:btn];
        
        btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = btn.frame =CGRectMake(35, 70, 129, 27);
        btn.tag = 2;
        [btn setBackgroundImage:[UIImage imageNamed:@"uploadrenren.png"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(OnShareBtnDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_SharePanel addSubview:btn];
        
        m_ShareCur = [[UIImageView alloc] initWithFrame:CGRectMake(3, 3, 21, 21)];
        m_ShareCur.image = [UIImage imageNamed:@"sharecur.png"];
        m_ShareCur.hidden = YES;
        [m_SharePanel addSubview:m_ShareCur];
        [m_ShareCur release];
        
        //选择封面
        m_ImgListPanel = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width, 0, self.frame.size.width, self.frame.size.height)];
        [self addSubview:m_ImgListPanel];
        [m_ImgListPanel release];
        
        bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, m_ImgListPanel.frame.size.width, m_ImgListPanel.frame.size.height)];
        bg.image = [UIImage imageNamed:@"appbg.jpg"];
        [m_ImgListPanel addSubview:bg];
        [bg release];
        
        bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, m_ImgListPanel.frame.size.width, 51)];
        bg.image = [UIImage imageNamed:@"barbg.png"];
        [m_ImgListPanel addSubview:bg];
        [bg release];
        
        bg = [[UIImageView alloc] initWithFrame:CGRectMake((m_ImgListPanel.frame.size.width-113)/2, 16, 113, 18)];
        bg.image = [UIImage imageNamed:@"draftcover.png"];
        [m_ImgListPanel addSubview:bg];
        [bg release];
        
        m_ImgList = [[CWaterFall alloc] initWithFrame:CGRectMake(0, 46, m_ImgListPanel.frame.size.width, m_ImgListPanel.frame.size.height-46) ColNum:3 WaterDropSize:CGSizeMake(ICON_WIDTH, ICON_HEIGHT)];
        m_ImgList.delegate = self;
        [m_ImgListPanel addSubview:m_ImgList];
        [m_ImgList release];
        
        /*m_TableView = [[UIView alloc] initWithFrame:CGRectMake(10, 60, frame.size.width-20, 120)];
        m_TableView.layer.cornerRadius = 8;
        m_TableView.layer.borderWidth  = 1;
        m_TableView.layer.borderColor  = [[UIColor lightGrayColor] CGColor];
        m_TableView.backgroundColor = [UIColor whiteColor];
        m_TableView.layer.shadowOffset = CGSizeMake(0, 1);
        m_TableView.layer.shadowColor = [[UIColor blackColor] CGColor];
        m_TableView.layer.shadowOpacity = 0.8;
        m_TableView.hidden = YES;
        [self addSubview:m_TableView];
        [m_TableView release];
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, m_Name.frame.size.height, m_TableView.frame.size.width, 1)];
        line.backgroundColor = [UIColor lightGrayColor];
        [m_TableView addSubview:line];
        [line release];
        
        line = [[UIView alloc] initWithFrame:CGRectMake(0, m_ResName.frame.origin.y+m_ResName.frame.size.height, m_TableView.frame.size.width, 1)];
        line.backgroundColor = [UIColor lightGrayColor];
        [m_TableView addSubview:line];
        [line release];*/
        
        m_AddrInfo = [[CAddrInfo alloc] init];
    }
    
    return self;
}

-(void)dealloc
{
    [m_AddrInfo release];
    
    [super dealloc];
}

- (void)WaterFallSelected:(id)object Index:(int)index
{
    self.m_Image.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/Documents/temp/%@", NSHomeDirectory(), [[CUploadPageCtrl DefaultUploadPage].m_ImgPathes objectAtIndex:index]]];
    [[CUploadPageCtrl DefaultUploadPage].m_ImgPathes exchangeObjectAtIndex:index withObjectAtIndex:[[CUploadPageCtrl DefaultUploadPage].m_ImgPathes count]-1];
    [CUploadPageCtrl DefaultUploadPage].m_strMainImg = [[CUploadPageCtrl DefaultUploadPage].m_ImgPathes objectAtIndex:0];
    [delegate DidUploadViewActived:self Command:2 Value1:[NSNumber numberWithInt:index] Value2:nil];
    ////NSLog(@"%@", [[CUploadPageCtrl DefaultUploadPage].m_ImgPathes objectAtIndex:[[CUploadPageCtrl DefaultUploadPage].m_ImgPathes count]-1]);
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(WaterFallHidden)];
    m_ImgListPanel.center = CGPointMake(self.frame.size.width/2+self.frame.size.width, m_ImgListPanel.center.y);
    [UIView commitAnimations];
}

-(void)WaterFallHidden
{
    [m_ImgList InitWaterFall];
}

- (void)DidWaterFallButtom:(id)object
{
    return;
}

-(void)OnShareBtnDown:(UIButton*)sender
{
    /*
    //sina
    if (0 == sender.tag)
    {
        //m_nShareType = 0;
    }
    //qq
    else if (1 == sender.tag)
    {
        //
    }
    //renren
    else
    {
        //
    }
    */
    UIImageView *img = [[m_SharePanel subviews] objectAtIndex:sender.tag];
    m_nShareType = sender.tag;
    m_ShareCur.center = img.center;
    m_ShareCur.hidden = NO;
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    return YES;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder];
        return NO;
    }
    else if (0 == range.length)
    {
        return YES;
    }
    else if ([textView.text length] > 140)
    {
        return NO;
    }
    
    return YES;
}

//-(void)SegClicked:(UISegmentedControl*)seg
-(void)SegClicked:(UIButton*)seg
{
    //int index = 10;
    
    //1-drop
    if (1 == seg.tag)
    {
        //index = 2;
        //[self CommitUpload];
        [m_Name resignFirstResponder];
        [m_ResName resignFirstResponder];
        [m_Addr resignFirstResponder];
        [m_Sum resignFirstResponder];
        
        [delegate DidUploadViewActived:self Command:1 Value1:nil Value2:nil];
    }
    //0-保存
    else if (0 == seg.tag)
    {
        //index = 1;
        [m_Name resignFirstResponder];
        [m_ResName resignFirstResponder];
        [m_Addr resignFirstResponder];
        [m_Sum resignFirstResponder];
        
        [delegate DidUploadViewActived:self Command:0 Value1:nil Value2:nil];
    }
    else {;}
}

-(void)OnButtonDown:(UIButton*)sender
{
    //[delegate DidUploadViewSelected:sender.tag View:self];
    //address of restaurant
    if (3 == sender.tag)
    {
        //保存用户当前位置
        m_AddrInfo.m_strCity     = [NSString stringWithFormat:@"%@", [CLocator DefaultLocator].m_AddrInfo.m_strCity];
        m_AddrInfo.m_strProvince = [NSString stringWithFormat:@"%@", [CLocator DefaultLocator].m_AddrInfo.m_strProvince];
        m_AddrInfo.m_strCountry  = [NSString stringWithFormat:@"%@", [CLocator DefaultLocator].m_AddrInfo.m_strCountry];
        m_AddrInfo.m_strSum      = [NSString stringWithFormat:@"%@", [CLocator DefaultLocator].m_AddrInfo.m_strSum];
        m_AddrInfo.m_fX          = [CLocator DefaultLocator].m_AddrInfo.m_fX;
        m_AddrInfo.m_fY          = [CLocator DefaultLocator].m_AddrInfo.m_fY;
        
        CRootCtrlManager *root = [CRootCtrlManager DefaultRootCtrl];
        CCitySelector *citysel = [[CCitySelector alloc] initWithFrame:CGRectMake(0, 0, root.view.frame.size.width, root.view.frame.size.height) ShowGrade:ToStreet];
        //citysel.m_Title.text = @"我在这里";
        //citysel.m_Title.font = [UIFont boldSystemFontOfSize:18];
        citysel.delegate = self;
        //citysel.m_NaviItem.leftBarButtonItem = nil;
        citysel.alpha = 0.0;
        [root.view addSubview:citysel];
        citysel.alpha = 1.0;
        [citysel release];
        
        [m_Name resignFirstResponder];
        [m_ResName resignFirstResponder];
        [m_Sum resignFirstResponder];
    }
}

-(void)DidCitySelectorActived:(int)index Object:(id)object
{
    CCitySelector *cityself = object;
    if ([cityself.m_City.text length] > 6)
    {
        m_Addr.text = [cityself.m_City.text substringFromIndex:6];
    }
    
    [cityself removeFromSuperview];
    
    CAddrInfo *info = [[CAddrInfo alloc] init];
    info.m_strCity     = [NSString stringWithFormat:@"%@", [CLocator DefaultLocator].m_AddrInfo.m_strCity];
    info.m_strProvince = [NSString stringWithFormat:@"%@", [CLocator DefaultLocator].m_AddrInfo.m_strProvince];
    info.m_strCountry  = [NSString stringWithFormat:@"%@", [CLocator DefaultLocator].m_AddrInfo.m_strCountry];
    info.m_strSum      = [NSString stringWithFormat:@"%@", [CLocator DefaultLocator].m_AddrInfo.m_strSum];
    info.m_fX          = [CLocator DefaultLocator].m_AddrInfo.m_fX;
    info.m_fY          = [CLocator DefaultLocator].m_AddrInfo.m_fY;
    
    //还原定位信息
    [CLocator DefaultLocator].m_AddrInfo.m_strCity      = [NSString stringWithFormat:@"%@", self.m_AddrInfo.m_strCity];
    [CLocator DefaultLocator].m_AddrInfo.m_strProvince  = [NSString stringWithFormat:@"%@", self.m_AddrInfo.m_strProvince];
    [CLocator DefaultLocator].m_AddrInfo.m_strCountry   = [NSString stringWithFormat:@"%@", self.m_AddrInfo.m_strCountry];
    [CLocator DefaultLocator].m_AddrInfo.m_strSum       = [NSString stringWithFormat:@"%@", self.m_AddrInfo.m_strSum];
    [CLocator DefaultLocator].m_AddrInfo.m_fY           = self.m_AddrInfo.m_fY;
    [CLocator DefaultLocator].m_AddrInfo.m_fX           = self.m_AddrInfo.m_fX;
    [CLocator DefaultLocator].m_Coordinate2D            = CLLocationCoordinate2DMake(self.m_AddrInfo.m_fX, self.m_AddrInfo.m_fY);
    
    self.m_AddrInfo.m_strCity     = [NSString stringWithFormat:@"%@", info.m_strCity];
    self.m_AddrInfo.m_strProvince = [NSString stringWithFormat:@"%@", info.m_strProvince];
    self.m_AddrInfo.m_strCountry  = [NSString stringWithFormat:@"%@", info.m_strCountry];
    self.m_AddrInfo.m_strSum      = [NSString stringWithFormat:@"%@", info.m_strSum];
    self.m_AddrInfo.m_fX          = info.m_fX;
    self.m_AddrInfo.m_fY          = info.m_fY;
    
    [info release];
    
    //[m_Name becomeFirstResponder];
}

-(void)TextFieldValueChanged:(UITextField*)textfield
{
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (0 == [textField.text length])
    {
        if ([string isEqualToString:@" "])
        {
            return NO;
        }
    }
    else if (1 == range.length)
    {
        return YES;
    }
    else if ([textField.text length] > 32)
    {
        return NO;
    }
    else if ([string isEqualToString:@" "])
    {
        NSRange rang = {range.location-1, 1};
        if ([string isEqualToString:[textField.text substringWithRange:rang]])
        {
            return NO;
        }
        
        return YES;
    }
    else if ([string isEqualToString:@"_"])
    {
        return NO;
    }

    NSString *emailRegex = @"^\\w+$"; 
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; 
    return [emailTest evaluateWithObject:string];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    /*if (m_Name == textField)
    {
        [m_ResName becomeFirstResponder];
    }
    else if (m_ResName == textField)
    {
        [m_Addr becomeFirstResponder];
    }
    else if (m_Addr == textField)
    {
        [m_Name becomeFirstResponder];
    }
    else {;}*/
    
    [textField resignFirstResponder];
    
    return YES;
}

-(void)textViewDidChange:(UITextView *)textView
{
    if ([textView.text length] > 140)
    {
        textView.text = [textView.text substringToIndex:140];
    }
}

-(void)OnCommitButtonDown:(UIButton*)sender
{
    [self CommitUpload];
}

-(void)CommitUpload
{
    if ([[CUploadPageCtrl DefaultUploadPage].m_ImgPathes count] > 0)
    {
        NSString*path  = nil;
        //NSLog(@"%@", [CUploadPageCtrl DefaultUploadPage].m_ImgPathes);
        for (NSString *str in [CUploadPageCtrl DefaultUploadPage].m_ImgPathes)
        {
            if (!m_bIsDraft)
            {
                path = [NSString stringWithFormat:@"%@/Documents/temp/%@", NSHomeDirectory(), str];
            }
            else 
            {
                CDraft *draft = [[CUploadPageCtrl DefaultUploadPage].m_DraftLst.m_Drafts objectAtIndex:[CUploadPageCtrl DefaultUploadPage].m_DraftLst.m_nSelDraft];
                ////NSLog(@"%@   %@", draft.m_strPath, str);
                path = [NSString stringWithFormat:@"%@/%@", draft.m_strPath, str];
            }
            [m_ImgList AddWaterDrop:[UIImage imageWithContentsOfFile:path]];
            //NSLog(@"%@", path);
        }
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        m_ImgListPanel.center = CGPointMake(self.frame.size.width/2, m_ImgListPanel.center.y);
        [UIView commitAnimations];
    }
    else 
    {
        [delegate DidUploadViewActived:self Command:2 Value1:nil Value2:nil];
    }
}

-(void)CancelUpload
{
    [delegate DidUploadViewActived:self Command:0 Value1:nil Value2:nil];
}

@end

